package com.jsgt.greekfire.ui.trading.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.CoinBean

/**
 * 委托列表
 */
class DelegationAdapter : BaseAdapter<CoinBean>() {

    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_delegation, parent, false)
        return VH(view)
    }

    inner class VH(itemView: View) : BaseViewHolder(itemView) {
        var stateTv: TextView? = null
        var date_tv: TextView? = null
        var cancel_tv: TextView? = null
        var amt_tv: TextView? = null
        var trading_tv: TextView? = null

        init {
            stateTv = itemView.findViewById(R.id.state_tv)
            date_tv = itemView.findViewById(R.id.date_tv)
            cancel_tv = itemView.findViewById(R.id.cancel_tv)
            amt_tv = itemView.findViewById(R.id.amt_tv)
            trading_tv = itemView.findViewById(R.id.trading_tv)
        }

        fun bindData(bean: CoinBean) {
//            date_tv?.text = bean.createTime
//            amt_tv?.text = "委托总量   ${bean.totalAmt} USDT        委托价格   ${bean.assetPrice} UTI"
//            trading_tv?.text = "已成交量   ${bean.exAmt} USDT        成交均价   ${bean.assetPrice} UTI"
//            if (bean.adType == 0) {
//                stateTv?.text = itemView.resources.getString(R.string.sell)
//                stateTv?.setBackgroundColor(
//                    ContextCompat.getColor(
//                        itemView.context, R.color.green_6AB578
//                    )
//                )
//            } else {
//                stateTv?.text = itemView.resources.getString(R.string.buy)
//                stateTv?.setBackgroundColor(
//                    ContextCompat.getColor(
//                        itemView.context, R.color.red_DE6C65
//                    )
//                )
//            }
            cancel_tv?.setOnClickListener {
                viewClickListener?.invoke(bean)
            }
        }
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        viewHolder.bindData(dataList()[position])
    }


}